// pages/register/register.js
const navBarHeight = wx.getSystemInfoSync().statusBarHeight + 44;
const request=require('../../util/request.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navBarHeight:navBarHeight,
    username:"",
    password:"",
    confirm_password:"",
    isAgree:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  backLayer(){
    wx.navigateBack()
  },
  bindKeyInput(e){
    console.log(e,"eeeeee")
    if(e.currentTarget.dataset.variable === 'username'){
      this.setData({username:e.detail.value})
    }else if(e.currentTarget.dataset.variable === 'password'){
      this.setData({password:e.detail.value})
    }else if(e.currentTarget.dataset.variable === 'confirm_password'){
      this.setData({confirm_password:e.detail.value})
    }
  },
  goLogin(){
    var that = this;
    console.log(this.data.username,"A")
    console.log(this.data.password,"S")
    console.log(this.data.confirm_password,"C")
      request.requestAjax('register',{
        username:this.data.username,
        password:this.data.password,
        phone:this.data.confirm_password,
      },"注册中",function(res){
        console.log(res,"resssssss")
          if(res.status==200){
            wx.showToast({
              title: '注册成功',
              icon:'success'
            });
            wx.setStorageSync('token', res.data.token);
            wx.setStorageSync('expires_time', res.data.expires_time);
            console.log(wx.getStorageSync('expires_time'));
            console.log(wx.getStorageSync('token'));
            setTimeout(function(){
              wx.switchTab({
                url: '/pages/index/index'
              })
            },1000);
     
          }else{
            wx.showToast({
              title: res.msg,
              icon:'none'
            });
          }
      },function(res){
        wx.showToast({
          title: "注册失败",
          icon:'none'
        });
      },false)
  }
})